//
//  UIView+CQPopupSelfCenterAction.m
//  AppCommonUICollect
//
//  Created by ciyouzen on 2019/8/13.
//  Copyright © 2019 dvlproad. All rights reserved.
//

#import "UIView+CQPopupSelfCenterAction.h"
#import <CJPopupContainer/CQPopupInfo+Effect.h>
#import <CQPopupContainerAnimation/UIView+CJPopupFrameAnimation.h>

@implementation UIView (CQPopupSelfCenterAction)



#pragma mark - 从window中间弹出当前视图的相关代码

#pragma mark Event
/**
 *  显示当前视图到window中间
 *
 *  @param popupViewHeight              弹出视图的高度(宽度已固定)
 */
- (void)cqCustom_self_popupInCenterWindowWithHeight:(CGFloat)popupViewHeight {
    //CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    //CGFloat popupViewWidth = screenWidth-2*15;
    CGFloat popupViewWidth = 290;
    CGSize popupViewSize = CGSizeMake(popupViewWidth, popupViewHeight);
    
    [self cqCustom_self_popupInCenterWindowWithSize:popupViewSize
                                       centerOffset:CGPointZero
                                         effectType:CQEffectForBlankViewWithBGColor
                                   tapBlankShouldHide:NO];
}


/*
 *  显示当前视图到window中间
 *
 *  @param popupViewSize            弹出视图的大小
 *  @param centerOffset             弹窗弹出位置的中心与window中心的偏移量
 *  @param effectType               effectType
 *  @param tapBlankShouldHide       点击背景是否应该隐藏
 */
- (void)cqCustom_self_popupInCenterWindowWithSize:(CGSize)popupViewSize
                                     centerOffset:(CGPoint)centerOffset
                                       effectType:(CQEffectFor)effectType
                               tapBlankShouldHide:(BOOL)tapBlankShouldHide
{
    // 执行显示弹窗的方法
    __weak typeof(self)weakSelf = self;
    CJBasePopupInfo *popupInfo = [CJBasePopupInfo addCenterSubviewToPopupSuperview:nil popupView:self withSize:popupViewSize centerOffset:centerOffset tapBlankComplete:^{
        if (tapBlankShouldHide) {
            [weakSelf cqCustom_self_popupHideCenter];
        }
    }];
    
    [CQPopupInfo configCenterPopupInfo:popupInfo effectType:effectType];
    
    [self cj_popupWithViewInfo:popupInfo isToBottom:NO];
}


/**
 *  从window中间隐藏当前视图
 */
- (void)cqCustom_self_popupHideCenter {
    [self cj_hidePopupView];
}

@end
